package com.fjut.pms.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import com.fjut.pms.dao.IBaseDao;
import com.fjut.pms.pojo.Department;
import com.fjut.pms.pojo.Employee;
import com.fjut.pms.pojo.TransferLog;
import com.fjut.pms.service.ITransferService;
import com.fjut.pms.utils.PageBean;

public class TransferServiceImpl implements ITransferService {
	private IBaseDao tranDao;

	public PageBean findTransefer(PageBean page, int id) {
		String hql = "from TransferLog tran where 1=1 ";
		String countHql = "select count(*) from TransferLog tran where 1=1 ";
		Map<String, Object> map = new HashMap<String, Object>();
		if (id != 0) {
			hql += "and employee_id=:id";
			countHql += "and employee_id=:id";
			map.put("id", id);
		}
		return tranDao.findPageByHql(page.getPageNo(), page.getPageSize(), hql,
				countHql, map);

	}
	public List findDeparts() {
		String hql = "from Department depart";
		return tranDao.findListByHql(hql);
	}
	public void save(TransferLog tran) {
		tranDao.saveOrUpdate(tran);
	}

	public IBaseDao getTranDao() {
		return tranDao;
	}

	public void setTranDao(IBaseDao tranDao) {
		this.tranDao = tranDao;
	}
	
	public List findEmpsByD(String depart) {
		List<Department> ds=(List<Department>) tranDao.findListByHql("from Department where name='"+depart+"'");
		Department d=ds.get(0);
		Iterator i=d.getEmployees().iterator();
		List l=new ArrayList();
		while(i.hasNext()){
			l.add((Employee)i.next());
		}
		return l;
	}
}
